package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzData;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption empJobData() {
        List<Map> mapList = empMapper.getJobData();
        log.info("mapList:{}", mapList);

        List<Object> jobList = mapList.stream()
                .map(map -> {
                    return map.get("pos");
                })
                .collect(Collectors.toList());

        List<Object> dataList = mapList.stream()
                .map(map -> {
                    return map.get("posCount");
                })
                .collect(Collectors.toList());

        return new JobOption(jobList,dataList);
    }



    @Override
    public List<Map> empGenderData() {
        List<Map> mapList = empMapper.getGenderData();
        return mapList;
    }



    @Override
    public List<Map> studentDegree() {
        List<Map> list = studentMapper.studentDegree();
        return list;
    }


    @Override
    public ClazzData studentData() {
        List<Map> sList = studentMapper.getClszzData();
        log.info("sList:{}", sList);

        List<Object> studentList = sList.stream()
                .map(map -> {
                    return map.get("clazzList");
                })
                .collect(Collectors.toList());

        List<Object> dataList = sList.stream()
                .map(map -> {
                    return map.get("dataList");
                })
                .collect(Collectors.toList());

        return new ClazzData(studentList,dataList);

    }
}
